package eo.main.gui.components.tree;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;

import javax.swing.tree.TreeNode;

import org.apache.commons.collections.iterators.IteratorEnumeration;

public class RootNode implements TreeNode {

    private final List<TreeNode> children = new ArrayList<TreeNode>();

    public RootNode(TreeNode... children) {
        for (TreeNode treeNode : children) {
            this.children.add(treeNode);
        }
    }

    public RootNode(Collection<? extends TreeNode> nodes) {
        this.children.addAll(nodes);
    }

    public Enumeration<?> children() {
        return new IteratorEnumeration(children.iterator());
    }

    public boolean getAllowsChildren() {
        return false;
    }

    public TreeNode getChildAt(int childIndex) {
        return children.get(childIndex);
    }

    public int getChildCount() {
        return children.size();
    }

    public int getIndex(TreeNode node) {
        return children.indexOf(node);
    }

    public TreeNode getParent() {
        return null;
    }

    public boolean isLeaf() {
        return children.isEmpty();
    }

}
